<?php
namespace app\admin\controller;

class Car extends Admin{
    public function __construct(){
        parent::__construct();
        $this->model = "Car";
        $this->assign("model",$this->model);
    }
    public function index(){
        $getData = input('param.');
        $pid = isset($getData['pid']) ? $getData['pid'] : 0;
        $whereData = 'pid='.$pid;
        if ($getData) {
            foreach ($getData as $k=>$v) {
                if ($k == 'pid' || !$v) {
                    continue;
                }
                $whereData .= '&'.$k.'='.$v;
            }
        }
        $this->assign('keywords', isset($getData['keywords']) ? $getData['keywords'] : '');
        $this->assign('pid', $pid);
        $this->assign("whereData",$whereData);
        return $this->fetch();
    }
    protected function get_where_map(){
        $whereData = input("param.whereData/s");
        $whereData = urldecode($whereData);
        $whereDatas = [];
        if ($whereData) {
            $whereData = explode('&', $whereData);
            foreach ($whereData as $v) {
                $r = explode('=', $v);
                if ($r[0] == 'keywords') {
                    $whereDatas['id|title|yeartype|salestate|sizetype'] = ['like', '%'.$r[1].'%'];
                }else{
                    $whereDatas[$r[0]] = $r[1];
                }
            }
        }
        return $whereDatas;
    }
    // public function data_show(){
    //     $pid = input("param.pid", 0);
    //     $page = input("param.page",1);
    //     $limit = input("param.limit",$this->default_page_items);
    //     $db = model($this->model);
    //     $offset = ($page - 1) * $limit;
    //     list($list,$where) = $db->get_list([],['pid'=>$pid],$limit,$offset);
    //     $count = $db->where('pid', $pid)->count();
    //     $return = [
    //         'code' => 0,
    //         'msg' => '',
    //         'count' => $count,
    //         'data' => $list,
    //     ];
    //     // trace($return);
    //     return json($return);
    // }
    public function add(){
        $pid = input("param.pid", 0);
        $pname = '顶级分类';
        if ($pid != 0) {
            $pname = model('Cartype')->where('id', $pid)->value('title');   
        }
        $this->assign('pid', $pid);
        $this->assign('pname', $pname);
        return $this->fetch();
    }
    public function edit(){
        $items = input("param.items");
        $db = model($this->model);
        $info = $db->get_data(['item_id' => $items]);
        $this->assign("info",$info);
        return $this->fetch();
    }
}